home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Collection of Tools & Utilities
/
Collection of Tools and Utilities.iso
/
dbase
/
lib19.zip
/
STATS.PRG
< prev
next >
Wrap
Text File
|
1992-06-25
|
26KB
|
595 lines
*-------------------------------------------------------------------------------
*-- Program...: STATS.PRG
*-- Programmer: Ken Mayer (KENMAYER) and Jay Parsons (JPARSONS)
*-- Date......: 06/25/1992
*-- Notes.....: Statistical Functions -- see README.TXT to include this
*-- library file in your system.
*-------------------------------------------------------------------------------
FUNCTION Samplevar
*-------------------------------------------------------------------------------
*-- Programmer..: Jay Parsons (Jparsons)
*-- Date........: 4/13/1992
*-- Notes.......: Finds sample variance of specified field of the current
*-- : database, using CALCULATE command.
*-- : The CALCULATE command calculates the population variance,
*-- : which is smaller by a factor of (n-1)/n.
*-- :
*-- Written for.: dBASE IV Version 1.5
*-- Rev. History: Original function 1990.
*-- : Modified to take optional parameter, 4/13/1992
*-- Calls : None
*-- Called by...: Any
*-- Usage.......: Samplevar( <cField> [, <cClause> ] )
*-- Example.....: ? Samplevar( "Balance", ".FOR..NOT. isblank( Balance )" )
*-- Returns : a numeric or float value, the sample variance, or .F. if
*-- : it cannot be calculated.
*-- : If any of the numeric items are floats, the result will be.
*-- Parameters..: cField, name of a numeric field of the current database
*-- : for which to calculate the sample variance
*-- : cClause, optional, a FOR, WHILE, TO, etc. clause
*-------------------------------------------------------------------------------
PARAMETERS cField, cCondition
PRIVATE fVar, nCount, cCond
IF pcount() = 2
cCond = " "+ cCondition
ELSE
cCond = ""
ENDIF
CALCULATE VAR( &cField ), CNT() TO fVar, nCount &cCond
RETURN iif( nCount > 1, fVar * nCount / ( nCount - 1 ), .F. )
*-- Eof: Samplevar()
FUNCTION Stny
*-------------------------------------------------------------------------------
*-- Programmer..: Jay Parsons (Jparsons)
*-- Date........: 11/13/1990
*-- Notes.......: Returns value of the standard normal distribution function
*-- : given a number of standard deviations from the mean.
*-- : This function is not useful alone. The standard normal
*-- : distribution function is the familiar bell-shaped curve
*-- : scaled so its mean is at 0, each standard deviation is 1
*-- : and the total area under the curve is 1. The function
*-- : Stnarea calls on this function to calculate the approximate
*-- : area (a fraction equal to percent of the total) under the
*-- : part of the curve lying betwen the mean and the given
*-- : number of standard deviations.
*-- :
*-- Written for.: dBASE IV
*-- Rev. History: None
*-- Calls : None
*-- Called by...: Any
*-- Usage.......: Stny( <nDevs> )
*-- Example.....: ? Stny( 1 )
*-- Returns : numeric value of the function.
*-- Parameters..: nDevs, standard deviations from the mean
*-------------------------------------------------------------------------------
PARAMETERS nDevs
RETURN exp( -nDevs * nDevs / 2 ) / sqrt( 2 * pi() )
*-- EoF: Stny()
FUNCTION Stnarea
*-------------------------------------------------------------------------------
*-- Programmer..: Jay Parsons (Jparsons)
*-- Date........: 11/13/1990
*-- Notes.......: Area of the standard normal distribution function between
*-- : mean and given number of standard deviations from the mean.
*-- :
*-- : What's it about? Well, College Board scores (originally)
*-- : were based on a normal distribution with a mean of 500 and
*-- : 100 points per standard deviation. Knowing that a 650
*-- : score is 1.5 standard deviations from the 500 mean, we
*-- : can calculate Stnarea( 1.5 ) as .4332. This tells us that
*-- : 43.32% of the scores lie between 650 and 500. Since 50%
*-- : lie below 500, a score of 650 beats 93.32% of the scores.
*-- :
*-- : The polynomial approximation used by this function is said
*-- : to be accurate to .00001, 1/1000 of one percent. Remember
*-- : to SET DECIMALS appropriately to view results.
*-- :
*-- Written for.: dBASE IV
*-- Rev. History: None
*-- Calls : Stny() Function in STATS.PRG
*-- Called by...: Any
*-- Usage.......: Stnarea( <nDevs> )
*-- Example.....: ? Stnarea( 1.5 )
*-- Returns : % of area between deviations given and the mean, 0<=a<.5.
*-- Parameters..: nDevs, standard deviations from the mean
*-------------------------------------------------------------------------------
PARAMETERS nDevs
PRIVATE nX, nV
nX = abs( nDevs )
nV = 1 / ( 1 + .33267 * nX )
RETURN .5 - Stny( nX ) * ( .4361836 * nV - .1201676 * nV * nV ;
+ .937298 * nV * nV * nV )
*-- EoF: Stnarea()
FUNCTION Stnz
*-------------------------------------------------------------------------------
*-- Programmer..: Jay Parsons (Jparsons)
*-- Date........: 11/13/1990
*-- Notes.......: A lookup table to find the values of "z", standard
*-- : deviations, corresponding to the most common areas inside a
*-- : given number of tails of the normal distribution function.
*-- :
*-- : Used in testing confidence intervals. If a sample of
*-- : light bulbs from a shipment shows an average life of 1150
*-- : hours, and the criterion for rejection of the shipment is
*-- : 95% confidence that the average life of all bulbs is less
*-- : than (a single tail) 1200 hours, the value 1.64485 returned
*-- : by this function is necessary to determine whether to
*-- : reject the shipment or not.
*-- :
*-- : Values of "z" that are not found in the table can be found
*-- : using Stndevs, below, but it is slow.
*-- :
*-- Written for.: dBASE IV
*-- Rev. History: None
*-- Calls : None
*-- Called by...: Any
*-- Usage.......: Stnz( <nProb>, <nTails> )
*-- Example.....: ? Stnz( .95, 1 )
*-- Returns : z, number of standard deviations from mean inside which
*-- : ( or to the side of which includes the mean, if one tail)
*-- : the given percentage of area will fall.
*-- : Returns -1 if no entry in table.
*-- Parameters..: nConf, confidence desired, 0 < nConf < 1
*-- : nTails, 1 or 2 = number of tails of curve of interest
*-------------------------------------------------------------------------------
PARAMETERS nConf, nTails
IF nTails # 1 .AND. nTails # 2
RETURN -1
ENDIF
DO CASE
CASE nConf = .95
RETURN iif( nTails = 1, 1.64485, 1.96010 )
CASE nConf = .99
RETURN iif( nTails = 1, 2.32676, 2.57648 )
CASE nConf = .995
RETURN iif( nTails = 1, 2.57648, 2.80794 )
CASE nConf = .999
RETURN iif( nTails = 1, 3.09147, 3.29202 )
OTHERWISE
RETURN -1
ENDCASE
*-- EoF: Stnz()
FUNCTION Stndiff
*-------------------------------------------------------------------------------
*-- Programmer..: Jay Parsons (Jparsons)
*-- Date........: 4/13/1992
*-- Notes.......: Determines whether hypothesis that sample of a given mean
*-- is different from expected mean is justified.
*--
*-- If nPopstd, the standard deviation of the population, is
*-- not known and nSample, the sample size, is greater than
*-- 30, the sample standard deviation may be used for nPopstd.
*--
*-- This function assumes the population is large relative to
*-- the sample or that the sampling is with replacement. If
*-- neither is true, the right side of the expression in the
*-- later return line should